import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		userInfo: uni.getStorageSync('userInfo'), //用户信息
		token: uni.getStorageSync('token'), //登录凭证
		tokena: uni.getStorageSync('tokena'), //临时登录凭证

		identity: uni.getStorageSync('identity') ? uni.getStorageSync('identity') :
		1, //用户身份标识 1用户 2服务端 3送货员 4入库员
		shop: uni.getStorageSync('shop'), //用户端选择门店信息

		user_order_active: 0, //用户订单列表标识
	},
	getters: {}, //vuex 计算属性
	mutations: {
		// 获取登录用户信息
		saveUserInfo(state, data) {
			state.userInfo = data
			uni.setStorageSync('userInfo', data)
		},
		// 获取登录token凭证
		saveToken(state, data) {
			state.token = data
			uni.setStorageSync('token', data)
		},
		// 获取登录临时tokena凭证
		saveTokena(state, data) {
			state.tokena = data
			uni.setStorageSync('tokena', data)
		},
		saveShop(state, data) { //保存用户端 选项的门店地址
			state.shop = data
			uni.setStorageSync('shop', data)
		},

		save_user_order_active(state, data) { //用户订单状态切换标识
			state.user_order_active = data
			uni.setStorageSync('user_order_active', data)
		},
		//退出登录  
		logout(state) {
			state.userInfo = ''
			state.token = ''
			uni.removeStorageSync('userInfo')
			uni.removeStorageSync('token')
		},
		// 获取登录临时tokena凭证
		delTokena(state) {
			uni.removeStorageSync('tokena')
		},

		// 保存用户身份
		saveIdentity(state, data) {
			state.identity = data
			uni.setStorageSync('identity', data)
		},
	},
	actions: {}
})
export default store
